package com.example.transaction_springboot.mapper;

import com.example.transaction_springboot.controller.request.BookRequest;
import com.example.transaction_springboot.entity.Book;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BookMapper {

    @Select("select * from book")
    List<Book> listBook();

    @Select("select * from book where name like concat('%',#{name},'%')" +
            "and book_no like concat('%',#{bookNo},'%') order by id desc limit #{pageNum},#{pageSize}")
    List<Book> selectByPage(BookRequest BookRequest);

    @Select("select COUNT(id) from book where name like concat('%',#{name},'%')" +
            "and book_no like concat('%',#{bookNo},'%')")
    int selectCountByPage(BookRequest bookRequest);

    @Insert("insert into book values(NULL,#{name},#{description},#{publishDate},#{author}," +
            "#{publisher},#{category},#{bookNo},#{cover},#{score},#{nums},#{createtime},#{updatetime})")
    void addBook(Book book);

    @Select("select * from book where id = #{id}")
    Book selectById(Integer id);

    @Update("update book set name=#{name},description = #{description},publish_date = #{publishDate},author = #{author}," +
            "publisher = #{publisher},category = #{category},book_no = #{bookNo},cover = #{cover}, " +
            "score = #{score},nums = #{nums}, updatetime = #{updatetime} where id=#{id}")
    void updateById(Book book);

    @Delete("delete from book where id = #{id}")
    void deleteById(Integer id);

    @Select("select  * from book where book_no = #{bookNo}")
    Book selectByBookNo(String bookNo);
}
